package practice06;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author Administrator
 * @version V1.0
 * @ProjectName:IntelliJ IDEA
 * @PackageName: practice06
 * @ClassName: Client
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2020/1/2 9:14
 * @Copyright 大牛版板所有
 */
public class Client {
    private static String fileName;

    public static String getFileName() {
        return fileName;
    }

    public static void setFileName(String fileName) {
        Client.fileName = fileName;
    }

    public static void main(String[] args) {
        DataInputStream dis = null;
        DataOutputStream dos = null;
        Socket socket = null;
        Scanner input = new Scanner(System.in);
        System.out.print("请输入你要上传图像的路径：");
        String path = input.next();
        System.out.print("请输入图片名称：");
        fileName = input.next();
        try {
            socket = new Socket("192.168.10.149",7000);
            dis = new DataInputStream(new FileInputStream(path));
            dos = new DataOutputStream(socket.getOutputStream());
            byte[] bytes = new byte[10240];
            int len = 0;
            while ((len=dis.read(bytes)) != -1){
                dos.write(bytes,0,len);
                dos.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (socket != null){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
